import axios from '@/libs/request/axios'
import {getUri} from "@/libs/tools";

// 添加类别
export const addClass = (params,path='') => {
    return axios.request({
        url: `/${path==''?getUri('template'):path}/templateClass/add`,
        data:params,
        method: 'post'
    })
}
// 编辑类别
export const editClass = (params,path='') => {
    return axios.request({
        url: `/${path==''?getUri('template'):path}/templateClass/edit`,
        data:params,
        method: 'post'
    })
}

// 删除类别
export const delClass = (classNo, params,path='') => {
    return axios.request({
        url: `/${path==''?getUri('template'):path}/templateClass/del/${classNo}`,
        data:params,
        method: 'delete'
    })
}

// 添加模板
export const addTemplate = (params,path='') => {
    return axios.request({
        url: `/${path==''?getUri('template'):path}/template/add`,
        data:params,
        method: 'post'
    })
}
// 编辑模板
export const editTemplate = (params,path='') => {
    return axios.request({
        url: `/${path==''?getUri('template'):path}/template/edit`,
        data:params,
        method: 'post'
    })
}

// 启用模板
export const enableTemplate = (id,path='') => {
    return axios.request({
        url: `/${path==''?getUri('template'):path}/template/enable/${id}`,
        method: 'post'
    })
}

// 禁用模板
export const disableTemplate = (id,path='') => {
    return axios.request({
        url: `/${path==''?getUri('template'):path}/template/disable/${id}`,
        method: 'post'
    })
}

// 获取类别模板树
export function getAllTemplateList(path='') {
    return axios.request({
        url: `/${path==''?getUri('template'):path}/templateClass/tree`,
        method: 'post',
    });
}

// 获取模板列表
export function queryTemplateList(query,path='') {
    return axios.request({
        url: `/${path==''?getUri('template'):path}/template/list`,
        method: 'post',
        data: query
    });
}

// 删除类别
export const delMapping = (mappingId,path='') => {
    return axios.request({
        url: `/${path==''?getUri('template'):path}/templateMapping/del/${mappingId}`,
        method: 'delete'
    })
}

// 添加模板
export const addMapping = (params,path='') => {
    return axios.request({
        url: `/${path==''?getUri('template'):path}/templateMapping/add`,
        data:params,
        method: 'post'
    })
}
// 编辑模板
export const editMapping = (params,path='') => {
    return axios.request({
        url: `/${path==''?getUri('template'):path}/templateMapping/edit`,
        data:params,
        method: 'post'
    })
}

// 获取模板映射列表
export function queryMappingList(query,path='') {
    return axios.request({
        url: `/${path==''?getUri('template'):path}/templateMapping/list`,
        method: 'post',
        data: query
    });
}

// 获取模板印章映射列表
export function querySealMappingList(query,path='') {
    return axios.request({
        url: `/${path==''?getUri('template'):path}/templateSeal/querySealMappingList`,
        method: 'post',
        data: query
    });
}

// 获取模板印章列表
export function querySealList(path='') {
    return axios.request({
        url: `/${path==''?getUri('template'):path}/templateSeal/querySealList`,
        method: 'post',
    });
}

// 添加印章
export const addSeal = (params,path='') => {
    return axios.request({
        url: `/${path==''?getUri('template'):path}/templateSeal/addSeal`,
        data:params,
        method: 'post'
    })
}

// 编辑印章
export const editSeal = (params,path='') => {
    return axios.request({
        url: `/${path==''?getUri('template'):path}/templateSeal/editSeal`,
        data:params,
        method: 'post'
    })
}

// 删除印章
export const delSeal = (params,path='') => {
    return axios.request({
        url: `/${path==''?getUri('template'):path}/templateSeal/delSeal`,
        data:params,
        method: 'post'
    })
}

// 获取模板签名映射列表
export function querySignMappingList(query,path='') {
    return axios.request({
        url: `/${path==''?getUri('template'):path}/templateSeal/querySignMappingList`,
        method: 'post',
        data: query
    });
}

// 添加签名
export const addSign = (params,path='') => {
    return axios.request({
        url: `/${path==''?getUri('template'):path}/templateSeal/addSign`,
        data:params,
        method: 'post'
    })
}

// 修改签名
export const editSign = (params,path='') => {
    return axios.request({
        url: `/${path==''?getUri('template'):path}/templateSeal/editSign`,
        data:params,
        method: 'post'
    })
}

// 删除签名
export const delSign = (params,path='') => {
    return axios.request({
        url: `/${path==''?getUri('template'):path}/templateSeal/delSign`,
        data:params,
        method: 'post'
    })
}

// 获取模板规则树
export function loadTemplateRuleTree(ruleGroup, ruleNo,path='') {
    return axios.request({
        url: `/${path==''?getUri('template'):path}/template/loadTemplateRuleTree/${ruleGroup}/${ruleNo}`,
        method: 'post'
    });
}
// 根据ruleId获取模板规则树
export function loadTemplateRuleTreeById(ruleId,path='') {
    return axios.request({
        url: `/${path==''?getUri('template'):path}/template/loadTemplateRuleTreeById`,
        params:{
            ruleId:ruleId
        },
        method: 'post'
    });
}
// 保存模板后激活最新规则
export const activateRules = (params,path='') => {
    return axios.request({
        url: `/${path==''?getUri('template'):path}/template/activateRules`,
        data:params,
        method: 'post'
    })
}

// 预览模板
export function preview(templateNo,path='') {
    return axios.request({
        url: `/${path==''?getUri('template'):path}/template/preview/${templateNo}`,
        method: 'get',
        responseType:"blob"
    });
}

// 同步数据
export function syncData(params) {
    return axios.request({
            url: `/${getUri('template')}/print/syncData`,
            data:params,
            method: 'post'
    });
}
// 根据ruleId失效模板
export function deActiveTemplateRuleById(ruleId,path='') {
    return axios.request({
        url: `/${path==''?getUri('template'):path}/template/deActiveTemplateRuleById/${ruleId}`,
        method: 'post'
    });
}


